#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;
const int maxn = 10005;

string s;
int a[maxn],n,cnt;

void read(){
	int tmp=0;
	cnt=1;
	char c;
	for(int i=0;i<s.size();i++){
		c=s[i];
		if(c==','){
			a[cnt++]=tmp;
			tmp=0;
		}else if((c-'0')>=0 && (c-'0')<=9){
			tmp=tmp*10+c-'0';
		}
	}
	a[cnt]=tmp;
}

bool check(int k){
	int re=1,tmp=0;
	for(int i=1;i<=cnt;i++){
		if(tmp+a[i]>k){
			re++;
			tmp=a[i];
		}else	tmp+=a[i];
		if(re>n)return false;
	}
	if(re>n)return false;
	else return true;
}

int main(){
	
	while(scanf("%d;",&n)!=EOF){
		int l=0,r=0,mid=0,ans=0;
		cin>>s;
		read();
		for(int i=1;i<=cnt;i++)r+=a[i];
		while(l<=r){
			mid=(l+r+1)/2;
			if(check(mid)){
				ans=mid;
				r=mid-1;
			}else{
				l=mid+1;
				ans=r;
			}
		}
		printf("%d\n",ans);
	}
}
